<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Db;
use \think\Loader;
class Post extends Controller
{
    public function index()
    {
    	$data=Db::table('post')
        ->alias('p')
        ->join('user u','p.uid = u.uid')
        ->join('cate c','p.class_id = c.cid')
        ->field('p.*,c.cname,u.avatar,u.username,u.level,u.is_approve')
        ->order('ctime desc')
        ->paginate('10');

        $cate = Db::table('cate')->select();

        return $this->fetch('',['data'=>$data,'cate'=>$cate]);
    }

    //禁用
    public function operate()
    {
    	$data = input('');
    	$operate = $data['operate'];
    	$status = $data['status'];
    	if ($status=='0') {
    		$status='1';
    	}else{
    		$status='0';
    	}
    	$res = Db::table('post')->where('pid','in',$data['data'])->update([$operate=>$status]);
    	// var_dump($res);exit;
    	if ($res) {
    		return ['error'=>0,'info'=>'操作成功'];
    	}else{
    		return ['error'=>1,'info'=>'操作失败,系统异常'];
    	}
    	
    }


    // 置顶
    // public function setTop($value='')
    // {
    // 	$data = input('');
    // 	$status = $data['status'];
    // 	if ($status=='0') {
    // 		$status='1';
    // 	}else{
    // 		$status='0';
    // 	}
    // 	$res = Db::table('post')->where('pid','in',$data['data'])->update(['is_top'=>$status]);
    // 	if ($res) {
    // 		return ['error'=>0,'info'=>'操作成功'];
    // 	}else{
    // 		return ['error'=>1,'info'=>'操作失败,系统异常'];
    // 	}
    // }

    //查询
    public function query($value='')
    {
    	# code...
    }



}
